/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clisp;

/**
 *
 * @author Ero
 */
import java.util.Scanner;
public class CLISP {

    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) {
        // TODO code application logic here
        boolean fueespacio;
        String ingreso;
        String ingreso2="";
        String[] ingresofinal;
        Scanner readln=new Scanner(System.in);
        System.out.println("Ingrese la instruccion que desea realizar");
        ingreso=readln.nextLine();
        ingreso=ingreso.toUpperCase();
        ingresofinal=ingreso.split(" ");
        boolean finished;
        do{
            finished=true;
            for(int x=0; x<ingresofinal.length; x++){
                if(!ingresofinal[x].isEmpty()){
                    if((ingresofinal[x].equals("DEFUN"))||((ingresofinal[x].equals("(DEFUN")))){
                        System.out.println("Encontre dfun");
                        ingresofinal[x+1]=ingresofinal[x+1].replace("(", " ( ");
                    }
                    if((ingresofinal[x].contains("("))){
                        System.out.println(ingresofinal[x].length());
                        ingreso2+=ingresofinal[x].replace("(", " ( ")+" ";


                    }else
                    {
                        System.out.println(ingresofinal[x].length());    
                        ingreso2+=ingresofinal[x].replace(")", " ) ")+" ";

                    }
                }
            }
            
            System.out.println(ingreso2);
            ingresofinal=ingreso2.split(" ");
            for(int y=0;y<ingresofinal.length; y++){
                if((ingresofinal[y].indexOf("(")!=-1)&&(ingresofinal[y].length()>1)){
                    finished=false;
                   
                }
                if((ingresofinal[y].indexOf(")")!=-1)&&(ingresofinal[y].length()>1)){
                    finished=false;
                }
               
            }
            ingreso2=null;
            ingreso2="";
        }while(!finished);
        for(int x=0; x<ingresofinal.length;x++){    
            if(!ingresofinal[x].isEmpty())
            System.out.println(ingresofinal[x]);
        }
        
    }
    
}
